#! /bin/sh
# PCP QA Test No. 654
# checks GFS2 PMDA functionality
#
# Copyright (c) 2013 - 2023 Red Hat. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_check_valgrind
[ $PCP_PLATFORM = linux ] || _notrun "GFS2 PMDA is Linux-specific (gfs2)"
[ -d $PCP_PMDAS_DIR/gfs2 ] || _notrun "gfs2 PMDA directory is not installed"

_cleanup()
{
    cd $here
    _restore_pmda_install gfs2
    $sudo rm -fr $tmp.root
    $sudo rm -f $tmp.*
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    $here/src/sortinst | \
    sed \
	-e "s,$PCP_PMDAS_DIR,PCP_PMDAS_DIR,g" \
    #end
}

# real QA test starts here
echo
echo "=== Installing GFS2 PMDA ===" | tee -a $seq_full
_prepare_pmda_install gfs2 || _exit 1
cd $PCP_PMDAS_DIR/gfs2
$sudo ./Install </dev/null >$tmp.out 2>&1
cat $tmp.out >> $seq_full

root=$tmp.root
export GFS2_SETUP_SYSFS="./sysfsdir/"
export GFS2_SETUP_DEBUGFS="./debugfsdir/"
export GFS2_SETUP_TRACE="./trace_pipe"
pmda=$PCP_PMDAS_DIR/gfs2/pmda_gfs2.so,gfs2_init
metrics=`pminfo -L -K clear -K add,115,$pmda gfs2 | LC_COLLATE=POSIX sort`
memcheck="gfs2.glocks.total gfs2.sbstats gfs2.holders.total gfs2.glstats.total gfs2.tracepoints.glock_state_change.total gfs2.latency.grant.all"

for tgz in $here/gfs2/gfs2-*.tgz
do
    [ $tgz = "gfs2/gfs2-*" ] && continue

    $sudo rm -fr $root
    mkdir $root || _fail "root in use when processing $tgz"
    cd $root
    $sudo tar xzf $tgz
    base=`basename $tgz`
    count=`echo $base | sed -e 's,.*-root-,,g' -e 's,.tgz$,,g'`
    cd $count/gfs2

    echo "== Checking metric descriptors and values - $base"
    pminfo -L -K clear -K add,115,$pmda -dfmtT $metrics 2>&1 \
    | _filter

    echo "== Checking with valgrind - $base"
    _run_valgrind pminfo -L -K clear -K add,115,$pmda -f $memcheck 2>&1 \
    | _filter

    echo && echo "== done" && echo
    cd $here
done
 
# cleanup ..
#
cd $PCP_PMDAS_DIR/gfs2
$sudo ./Remove </dev/null >/dev/null 2>&1

# success, all done
status=0
exit
